﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinFormsApp1
{
    public partial class FormAdd : Form
    {
        public int orderNo;//订单号
        public string cname;//商品名称
        public string customername;//客户
        public int amount;//订单金额
        public int numbers;//订单有多少个订单明细
        public List<OrderExer.OrderDetails> orderDetails = new List<OrderExer.OrderDetails>();

        public FormAdd()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            orderNo = int.Parse(textBox1.Text);
            cname = textBox3.Text;
            customername = textBox2.Text;
            amount = int.Parse(textBox4.Text);
            numbers = int.Parse(textBox5.Text);
            for (int i = 1; i <= numbers; i++)
            {
                FormOrderDetail formOrderDetail = new FormOrderDetail();
                formOrderDetail.ShowDialog();
                //Console.WriteLine("请输入第" + i + "个订单明细的客户年龄");
                string cusAge = formOrderDetail.age;
                //Console.WriteLine("请输入第" + i + "个订单明细的商品生产日期");
                string date = formOrderDetail.date;
                OrderExer.OrderDetails orderDetail = new OrderExer.OrderDetails(customername, cusAge, cname, date);
                bool flag = false;

                foreach (OrderExer.OrderDetails details in orderDetails)
                {
                    if (orderDetail.Equals(details))
                    {
                        flag = true;
                        MessageBox.Show("该订单明细已存在，无法添加", "警告");
                        this.numbers--;
                        break;
                    }
                }
                if (!flag)
                {
                    orderDetails.Add(orderDetail);
                }
            }
            this.Close();
        }
    }
}
